package com.approval.approvalapp.center.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.approval.approvalapp.R;
import com.approval.approvalapp.center.acitivty.BjtjActivity;
import com.approval.approvalapp.center.acitivty.ConsultCensusActivity;
import com.approval.approvalapp.center.acitivty.ExceptionReviseActivity;
import com.approval.approvalapp.center.acitivty.HyspActivity;
import com.approval.approvalapp.center.acitivty.JyhfActivity;
import com.approval.approvalapp.center.acitivty.MonthCommentActivity;
import com.approval.approvalapp.center.acitivty.ProvinceCensusActivity;
import com.approval.approvalapp.center.acitivty.ThingsCensusActivity;
import com.approval.approvalapp.center.acitivty.ThingsProductivityActivity;
import com.approval.approvalapp.center.acitivty.ZdrwActivity;
import com.approval.approvalapp.center.bean.TodayThingBean;
import com.approval.approvalapp.center.tz.FbtzActivity;
import com.approval.approvalapp.index.cygn.hys.HysListActivity;
import com.approval.approvalapp.index.cygn.qjshenqing.QjShenqingActivity;
import com.approval.approvalapp.index.cygn.wzly.WzlyActivity;
import com.approval.approvalapp.index.cygn.yjcn.JyyjActivity;
import com.approval.approvalapp.index.dbsx.qjsp.QjSpActivity;
import com.approval.approvalapp.index.dbsx.wzsp.activity.WzSpActivity;
import com.approval.approvalapp.util.DensityUtil;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

public class CenterCardAdapter extends BaseRecycleListAdapter<TodayThingBean> {


    public CenterCardAdapter(List mList, Context context) {
        super(mList, context);
    }

    @Override
    public int getLayoutId() {
        return R.layout.center_card_item;
    }

    @Override
    public RecyclerView.ViewHolder createHolder(View view) {
        return new ViewHolder(view);
    }

    @Override
    protected void onBindDefaultViewHolder(RecyclerView.ViewHolder holder, TodayThingBean bean, int position) {
        if (holder instanceof ViewHolder) {
            ((ViewHolder) holder).setData(bean);
        }
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.iv_logo)
        ImageView ivLogo;
        @Bind(R.id.tv_title)
        TextView tvTitle;
        @Bind(R.id.tv_red)
        TextView tvRed;
        @Bind(R.id.root)
        RelativeLayout rlItem;


        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }

        public void setData(TodayThingBean bean) {

            int number = bean.getNumber();
            int imagePath = bean.getImagePath();
            final String title = bean.getTitle();
            final String id = bean.getId();


            tvTitle.setText(title);
            ivLogo.setImageResource(imagePath);

            if (number == 0) {
                tvRed.setVisibility(View.GONE);
            } else {
                if (number > 100) {
                    tvRed.setText("99");
                } else {
                    tvRed.setText(number + "");
                }
                tvRed.setVisibility(View.VISIBLE);
            }

            rlItem.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent();
                    if (TextUtils.isEmpty(id)) {
                        switch (title) {
                            case "省级大厅统计":
                                ProvinceCensusActivity.goInto(context);
                                break;
                            case "月度评价":
                                MonthCommentActivity.goInto(context);
                                break;
                            case "咨询投诉统计":
                                ConsultCensusActivity.goInto(context);
                                break;
                            case "事项统计":
                                ThingsCensusActivity.goInto(context);
                                break;
                            case "办件效率统计":
                                ThingsProductivityActivity.goInto(context);
                                break;
                            case "办件统计":
                                BjtjActivity.goInto(context);
                                break;
                        }
                    } else {
                        switch (id) {
                            case "1":
                                intent.setClass(context, QjSpActivity.class);
                                intent.putExtra("uriid", id);
                                context.startActivity(intent);
                                break;
                            case "2":
                                intent.setClass(context, QjSpActivity.class);
                                intent.putExtra("uriid", id);
                                context.startActivity(intent);
                                break;
                            case "3":
                                intent.setClass(context, WzSpActivity.class);
                                intent.putExtra("uriid", id);
                                context.startActivity(intent);
                                break;
                            case "4":
                                intent.setClass(context, WzSpActivity.class);
                                intent.putExtra("uriid", id);
                                context.startActivity(intent);
                                break;
                            case "5":
                                intent.setClass(context, HyspActivity.class);
                                context.startActivity(intent);
                                break;
                            case "6":
                                intent.setClass(context, QjShenqingActivity.class);
                                context.startActivity(intent);
                                break;
                            case "7":
                                intent.setClass(context, WzlyActivity.class);
                                context.startActivity(intent);
                                break;
                            case "8":
                                intent.setClass(context, HysListActivity.class);
                                context.startActivity(intent);
                                break;
                            case "9":
                                intent.setClass(context, ZdrwActivity.class);
                                context.startActivity(intent);
                                break;
                            case "10":
                                intent.setClass(context, JyhfActivity.class);
                                context.startActivity(intent);
                                break;
                            case "11":
                                intent.setClass(context, ExceptionReviseActivity.class);
                                intent.putExtra("is_select", "1");
                                context.startActivity(intent);
                                break;
                            case "12":
                                intent.setClass(context,FbtzActivity.class);
                                context.startActivity(intent);
                                break;

                        }
                    }
                }
            });
        }
    }
}
